#include "HttpServer.hpp"


using namespace LogModule;

void Login(HttpRequest &req, HttpResponse &resp)
{
    // 根据req 构造resp
    LOG(DEBUG, "进入登入模块 %s, %s\n",req.Path().c_str(), req.Args().c_str());
    std::string req_args = req.Args();

    // 1. 解析参数格式，得到参数

    // 2. 访问数据库，验证对应的用户是否合法

    // 3. 登入成功
    std::string body = req.GetContent("wwwroot/success.html");
    resp.SetCode(200);
    resp.SetHeader("Content-Length", std::to_string(body.size()));
    resp.SetHeader("Content-Type", "text/html");
    resp.SetHeader("Set-Cookie", "username=111111&passwd=123456;");
    resp.SetBody(body);

    // resp.SetCode(302);
    // resp.SetHeader("Location", "/");
}

int main()
{
    auto httpserver = std::make_unique<HttpServer>(8080);

    httpserver->Resgiter("/login", Login); // restful风格网络请求接口

    httpserver->Start();
    return 0;
}